home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWFiles / FWFileSp.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  14.3 KB  |  493 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFileSp.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWFILESP_H
  13. #include "FWFileSp.h"
  14. #endif
  15.  
  16. #ifndef FWFILESY_H
  17. #include "FWFileSy.h"
  18. #endif
  19.  
  20. #ifndef FWEXCLIB_H
  21. #include "FWExcLib.h"
  22. #endif
  23.  
  24. #ifndef FWBNDSTR_H
  25. #include "FWBndStr.h"
  26. #endif
  27.  
  28. #if defined(FW_BUILD_MAC) && !defined(__ERRORS__)
  29. #include <Errors.h>
  30. #endif
  31.  
  32. #if defined(FW_BUILD_MAC) && !defined(__FINDER__)
  33. #include <Finder.h>
  34. #endif
  35.  
  36. #if defined(FW_BUILD_WIN) && !defined(__IO_H)
  37. #include <io.h>
  38. #endif
  39.  
  40.  
  41. #ifdef FW_BUILD_MAC
  42. #pragma segment FW_PFileSpecification
  43. #endif
  44.  
  45. //========================================================================================
  46. //    Template instantiations
  47. //========================================================================================
  48.  
  49. #include "FWSOMPtr.tpp"
  50.  
  51. FW_DEFINE_AUTO_TEMPLATE(FW_TSOMPtr, FW_OFileSpecification)
  52. FW_DEFINE_AUTO_TEMPLATE(FW_TSOMPtr, FW_ODirectorySpecification)
  53.  
  54. #if FW_USE_TEMPLATE_PRAGMAS
  55. #pragma template_access public
  56. #pragma template FW_TSOMPtr<FW_OFileSpecification>
  57. #pragma template FW_TSOMPtr<FW_ODirectorySpecification>
  58. #endif
  59.  
  60. #if FW_ANSI_TEMPLATE_INTANSTIATION
  61. template class FW_TSOMPtr<FW_OFileSpecification>;
  62. template class FW_TSOMPtr<FW_ODirectorySpecification>;
  63. #endif
  64.  
  65. //========================================================================================
  66. //  CLASS FW_PFileSpecification
  67. //========================================================================================
  68.  
  69. FW_DEFINE_AUTO(FW_PFileSpecification)
  70.  
  71. //----------------------------------------------------------------------------------------
  72. //    FW_PFileSpecification::FW_PFileSpecification
  73. //
  74. //  Create a file specification from a directory and a file name.  
  75. //----------------------------------------------------------------------------------------
  76.  
  77. FW_PFileSpecification::FW_PFileSpecification(Environment *ev,
  78.                                              FW_ODirectorySpecification* directory,
  79.                                              const FW_CString& fileName)
  80. {
  81.     FW_OFileSpecification *theFileSpec = new FW_OFileSpecification;
  82.  
  83.     SetRep(ev, theFileSpec);
  84.     theFileSpec->InitFromDirectoryAndName(ev, directory, fileName);
  85.  
  86.     FW_END_CONSTRUCTOR
  87. }
  88.  
  89.  
  90. //----------------------------------------------------------------------------------------
  91. //    FW_PFileSpecification::FW_PFileSpecification
  92. //
  93. //    Initialize the specification with fileName.  If fileName is a partial pathname, then
  94. //    the current working directory is used.
  95. //----------------------------------------------------------------------------------------
  96.  
  97. FW_PFileSpecification::FW_PFileSpecification(Environment *ev, const FW_CString& pathName)
  98. {
  99.     Clone(ev, pathName);
  100.  
  101.     FW_END_CONSTRUCTOR
  102. }
  103.  
  104.  
  105. //----------------------------------------------------------------------------------------
  106. //    FW_PFileSpecification::FW_PFileSpecification
  107. //
  108. //  Acquisition constructor
  109. //----------------------------------------------------------------------------------------
  110.  
  111. FW_PFileSpecification::FW_PFileSpecification(Environment *ev, FW_OFileSpecification* specification)
  112. {
  113.     SetRep(ev, specification);
  114.  
  115.     FW_END_CONSTRUCTOR
  116. }
  117.  
  118.  
  119. //----------------------------------------------------------------------------------------
  120. //    FW_PFileSpecification::FW_PFileSpecification
  121. //
  122. //  Copy constructor
  123. //----------------------------------------------------------------------------------------
  124.  
  125. FW_PFileSpecification::FW_PFileSpecification(const FW_PFileSpecification& specificationPtr)
  126. {
  127.     FW_SOMEnvironment ev;
  128.  
  129.     Clone(ev, specificationPtr);
  130.  
  131.     FW_END_CONSTRUCTOR
  132. }
  133.  
  134.  
  135. //----------------------------------------------------------------------------------------
  136. //    FW_PFileSpecification::~FW_PFileSpecification
  137. //----------------------------------------------------------------------------------------
  138.  
  139. FW_PFileSpecification::~FW_PFileSpecification()
  140. {
  141.     FW_START_DESTRUCTOR
  142. }
  143.  
  144.  
  145. //----------------------------------------------------------------------------------------
  146. //    FW_PFileSpecification::operator==
  147. //
  148. //  Equality operator.  Compares the location of each file.  If the location's match, then
  149. //    the file is a match.
  150. //  Note that the Windows side is case insensitive.  On the Mac, FSSMakeFSSpec should
  151. //    normalize file names so conversion should not be necessary.
  152. //----------------------------------------------------------------------------------------
  153.  
  154. FW_Boolean FW_PFileSpecification::operator==(FW_OFileSpecification* theOtherFile) const
  155. {
  156.     FW_SOMEnvironment ev;
  157.  
  158.     return GetRep()->IsSameAs(ev, theOtherFile);
  159. }
  160.  
  161.  
  162. //----------------------------------------------------------------------------------------
  163. //    FW_PFileSpecification::operator=
  164. //
  165. //  Copies info over from pre-verified file specification.  Shouldn't need to do any 
  166. //    checks.
  167. //----------------------------------------------------------------------------------------
  168.  
  169. FW_PFileSpecification& FW_PFileSpecification::operator=(const FW_PFileSpecification& theOtherFile)
  170. {
  171.     FW_SOMEnvironment ev;
  172.  
  173.     Clone(ev, theOtherFile);
  174.  
  175.     return (*this);
  176. }
  177.  
  178.  
  179. //----------------------------------------------------------------------------------------
  180. //    FW_PFileSpecification::operator=
  181. //
  182. //    Set the name of the file.  This only changes the name, it doesn't change the previous
  183. //    path.  Reverifies the path with the new fileName.
  184. //----------------------------------------------------------------------------------------
  185.  
  186. FW_PFileSpecification& FW_PFileSpecification::operator=(const FW_CString& fileName)
  187. {
  188.  
  189.     FW_SOMEnvironment ev;
  190.  
  191.     Clone(ev, fileName);
  192.  
  193.     return (*this);
  194. }
  195.  
  196.  
  197. #ifdef FW_BUILD_MAC
  198. //----------------------------------------------------------------------------------------
  199. //    FW_PFileSpecification::FW_PFileSpecification
  200. //
  201. //    Macintosh FSSpec constructor.  
  202. //----------------------------------------------------------------------------------------
  203.  
  204. FW_PFileSpecification::FW_PFileSpecification(Environment *ev, const FSSpec& macSpec)
  205. {
  206.     Clone(ev, macSpec);
  207.  
  208.     FW_END_CONSTRUCTOR
  209. }
  210. #endif
  211.  
  212.  
  213. #ifdef FW_BUILD_MAC
  214. //----------------------------------------------------------------------------------------
  215. //    FW_PFileSpecification::operator=
  216. //----------------------------------------------------------------------------------------
  217.  
  218. FW_PFileSpecification& FW_PFileSpecification::operator=(const FSSpec& macSpec)
  219. {
  220.     FW_SOMEnvironment ev;
  221.  
  222.     Clone(ev, macSpec);
  223.  
  224.     return (*this);
  225. }
  226. #endif
  227.  
  228.  
  229. //----------------------------------------------------------------------------------------
  230. //    FW_PFileSpecification::Clone
  231. //
  232. //  Copy constructor
  233. //----------------------------------------------------------------------------------------
  234.  
  235. void FW_PFileSpecification::Clone(Environment *ev, FW_OFileSpecification* specification)
  236. {
  237.     if (GetRep() == 0)
  238.         SetRep(ev, new FW_OFileSpecification);
  239.  
  240.     GetRep()->AssignOFileSpecification(ev, specification);
  241. }
  242.  
  243.  
  244. //----------------------------------------------------------------------------------------
  245. //    FW_PFileSpecification::Clone
  246. //
  247. //  Copy constructor
  248. //----------------------------------------------------------------------------------------
  249.  
  250. void FW_PFileSpecification::Clone(Environment *ev, const FW_CString& fileName)
  251. {
  252.     if (GetRep() == 0)
  253.         SetRep(ev, new FW_OFileSpecification);
  254.  
  255.     GetRep()->InitFromFileName(ev, fileName);
  256. }
  257.  
  258.  
  259. #ifdef FW_BUILD_MAC
  260. //----------------------------------------------------------------------------------------
  261. //    FW_PFileSpecification::Clone
  262. //
  263. //  Copy constructor
  264. //----------------------------------------------------------------------------------------
  265.  
  266. void FW_PFileSpecification::Clone(Environment *ev, const FSSpec& macSpec)
  267. {
  268.     if (GetRep() == 0)
  269.         SetRep(ev, new FW_OFileSpecification);
  270.  
  271.     GetRep()->AssignFileSpec(ev, (FSSpec*) &macSpec);
  272. }
  273. #endif
  274.  
  275.  
  276.  
  277. //========================================================================================
  278. //  CLASS FW_PDirectorySpecification
  279. //========================================================================================
  280.  
  281. #ifdef FW_BUILD_MAC
  282. #pragma segment FW_PDirectorySpecification
  283. #endif
  284.  
  285. FW_DEFINE_AUTO(FW_PDirectorySpecification)
  286.  
  287. //----------------------------------------------------------------------------------------
  288. //    FW_PDirectorySpecification::FW_PDirectorySpecification
  289. //
  290. //  Specifies the current working directory.
  291. //----------------------------------------------------------------------------------------
  292.  
  293. FW_PDirectorySpecification::FW_PDirectorySpecification()
  294. {
  295.     FW_SOMEnvironment ev;
  296.     FW_ODirectorySpecification *theFileSpec = new FW_ODirectorySpecification;
  297.  
  298.     SetRep(ev, theFileSpec);
  299.  
  300.     FW_END_CONSTRUCTOR
  301. }
  302.  
  303.  
  304. //----------------------------------------------------------------------------------------
  305. //    FW_PDirectorySpecification::FW_PDirectorySpecification
  306. //
  307. //  Copy constructor.
  308. //----------------------------------------------------------------------------------------
  309.  
  310. FW_PDirectorySpecification::FW_PDirectorySpecification(Environment *ev, FW_ODirectorySpecification* theFileSpec)
  311. {
  312.     SetRep(ev, theFileSpec);
  313.  
  314.     FW_END_CONSTRUCTOR
  315. }
  316.  
  317.  
  318. //----------------------------------------------------------------------------------------
  319. //    FW_PDirectorySpecification::FW_PDirectorySpecification
  320. //
  321. //  Copy constructor.
  322. //----------------------------------------------------------------------------------------
  323.  
  324. FW_PDirectorySpecification::FW_PDirectorySpecification(const FW_PDirectorySpecification& other)
  325. {
  326.     FW_SOMEnvironment ev;
  327.  
  328.     Clone(ev, other);
  329.  
  330.     FW_END_CONSTRUCTOR
  331. }
  332.  
  333.  
  334. //----------------------------------------------------------------------------------------
  335. //    FW_PDirectorySpecification::FW_PDirectorySpecification
  336. //
  337. //  Specifies the path by string.  directoryName can be either a full or partial path
  338. //    name.  
  339. //----------------------------------------------------------------------------------------
  340.  
  341. FW_PDirectorySpecification::FW_PDirectorySpecification(Environment* ev, const FW_CString& directoryName)
  342. {
  343.     Clone(ev, directoryName);
  344.  
  345.     FW_END_CONSTRUCTOR
  346. }
  347.  
  348.  
  349. //----------------------------------------------------------------------------------------
  350. //    FW_PDirectorySpecification::~FW_PDirectorySpecification
  351. //----------------------------------------------------------------------------------------
  352.  
  353. FW_PDirectorySpecification::~FW_PDirectorySpecification()
  354. {
  355.     FW_START_DESTRUCTOR
  356. }
  357.  
  358.  
  359. //----------------------------------------------------------------------------------------
  360. //    FW_PDirectorySpecification::operator==
  361. //----------------------------------------------------------------------------------------
  362. FW_Boolean FW_PDirectorySpecification::operator==(FW_ODirectorySpecification* theOtherDir) const
  363. {
  364.     FW_SOMEnvironment ev;
  365.  
  366.     return GetRep()->IsSameAs(ev, theOtherDir);
  367. }
  368.  
  369.  
  370. //----------------------------------------------------------------------------------------
  371. //    FW_PDirectorySpecification::operator=
  372. //----------------------------------------------------------------------------------------
  373. FW_PDirectorySpecification& FW_PDirectorySpecification::operator=(const FW_PDirectorySpecification& theOtherDir)
  374. {
  375.     FW_SOMEnvironment ev;
  376.  
  377.     Clone(ev, theOtherDir);
  378.  
  379.     return (*this);
  380. }
  381.  
  382.  
  383. //----------------------------------------------------------------------------------------
  384. //    FW_PDirectorySpecification::operator=
  385. //
  386. //  Set the name of the directory to the value specified in directoryName.  directoryName
  387. //    should not contain any path delimiters.
  388. //----------------------------------------------------------------------------------------
  389. FW_PDirectorySpecification& FW_PDirectorySpecification::operator=(const FW_CString& directoryName)
  390. {
  391.     FW_SOMEnvironment ev;
  392.  
  393.     Clone(ev, directoryName);
  394.  
  395.     return (*this);
  396. }
  397.  
  398.  
  399. //----------------------------------------------------------------------------------------
  400. //    FW_PDirectorySpecification::operator+=
  401. //
  402. //  Adds directoryName on to the end of this directory.
  403. //  In this case, the new name is assigned to the internal FileSpec, where it is interpeted
  404. //    as a partial path.
  405. //----------------------------------------------------------------------------------------
  406. FW_PDirectorySpecification& FW_PDirectorySpecification::operator+=(const FW_CString& directoryName)
  407. {
  408.     FW_SOMEnvironment ev;
  409.  
  410.     GetRep()->AppendDirectoryName(ev, directoryName);
  411.  
  412.     return (*this);
  413. }
  414.  
  415.  
  416. #ifdef FW_BUILD_MAC
  417. //----------------------------------------------------------------------------------------
  418. //    FW_PDirectorySpecification::FW_PDirectorySpecification
  419. //----------------------------------------------------------------------------------------
  420.  
  421. FW_PDirectorySpecification::FW_PDirectorySpecification(Environment* ev, const FSSpec& macSpec)
  422. {
  423.     Clone(ev, macSpec);
  424.  
  425.     FW_END_CONSTRUCTOR
  426. }
  427. #endif
  428.  
  429.  
  430. #ifdef FW_BUILD_MAC
  431. //----------------------------------------------------------------------------------------
  432. //    FW_PDirectorySpecification::operator=
  433. //
  434. //  Copies the Macintosh FSSpec for this directory into specification.
  435. //----------------------------------------------------------------------------------------
  436.  
  437. FW_PDirectorySpecification& FW_PDirectorySpecification::operator=(const FSSpec& macSpec)
  438. {
  439.     FW_SOMEnvironment ev;
  440.  
  441.     Clone(ev, macSpec);
  442.  
  443.     return (*this);
  444. }
  445. #endif
  446.  
  447.  
  448. //----------------------------------------------------------------------------------------
  449. //    FW_PDirectorySpecification::Clone
  450. //
  451. //  Copy constructor
  452. //----------------------------------------------------------------------------------------
  453.  
  454. void FW_PDirectorySpecification::Clone(Environment *ev, FW_ODirectorySpecification* specification)
  455. {
  456.     if (GetRep() == 0)
  457.         SetRep(ev, new FW_ODirectorySpecification);
  458.  
  459.     GetRep()->AssignOFileSpecification(ev, specification);
  460. }
  461.  
  462.  
  463. //----------------------------------------------------------------------------------------
  464. //    FW_PDirectorySpecification::Clone
  465. //
  466. //  Copy constructor
  467. //----------------------------------------------------------------------------------------
  468.  
  469. void FW_PDirectorySpecification::Clone(Environment *ev, const FW_CString& fileName)
  470. {
  471.     if (GetRep() == 0)
  472.         SetRep(ev, new FW_ODirectorySpecification);
  473.  
  474.     GetRep()->InitFromFileName(ev, fileName);
  475. }
  476.  
  477.  
  478. #ifdef FW_BUILD_MAC
  479. //----------------------------------------------------------------------------------------
  480. //    FW_PDirectorySpecification::Clone
  481. //
  482. //  Copy constructor
  483. //----------------------------------------------------------------------------------------
  484.  
  485. void FW_PDirectorySpecification::Clone(Environment *ev, const FSSpec& macSpec)
  486. {
  487.     if (GetRep() == 0)
  488.         SetRep(ev, new FW_ODirectorySpecification);
  489.  
  490.     GetRep()->AssignFileSpec(ev, (FSSpec*) &macSpec);
  491. }
  492. #endif
  493.